<template>
    <div>
      <h1>病房添加</h1>
      <table class="table table-bordered">
        <tbody>
            <tr>
                <td align="right">病房号</td>
                <td>
                    <input type="text" v-model="query.wardName"/>
                </td>
            </tr>
            <tr>
                <td align="right">所属科室</td>
                <td>
                    <select v-model="query.departmentName">
                        <option value="">请选择</option>
                        <option :value="item.departmentName" v-for="item in list">{{ item.departmentName }}</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">床位数</td>
                <td>
                    <input type="number" min="1" v-model="query.bednumber"/>
                </td>
            </tr>
            <tr>
                <td align="right">状态</td>
                <td>
                    <input type="radio" name="states" :value="0" v-model="query.state"/>启用
                    <input type="radio" name="states" :value="1" v-model="query.state"/>维修
                </td>
            </tr>
            <tr>
                <td align="right">空床位数</td>
                <td>
                    <input type="number" min="0" v-model="query.nullBedNumber"/>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="添加" class="btn btn-success" @click="ok"/>
                </td>
            </tr>
        </tbody>
      </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,reactive,onMounted } from 'vue';
import moment from 'moment';
import { useRoute,useRouter } from 'vue-router';
//接收值
const route=useRoute();
//跳转页面
const router=useRouter();

let query:any=reactive
({
  "wardName": "",
  "departmentName": "",
  "bednumber": "",
  "state": 0,
  "nullBedNumber": 0
})

let list:any=ref([])


onMounted(()=>{
  showlist();
})
//显示科室信息
const showlist=()=>
{
   axios
   ({
      url:'/api/Department/ShowDepartment',
      method:'get'
   })
   .then(res=>{
    list.value=res.data;
   })
   .catch(err=>{

   })
}


const ok=()=>
{
    if(query.wardName=="")
    {
        alert("病房号不能为空");
        return;
    }
    if(query.wardName.length>6)
    {
        alert("病房名称不能超过6个字");
        return;
    }
    if(query.departmentName=="")
    {
        alert("科室不能为空");
        return;
    }
    if(query.bednumber=="")
    {
        alert("床位数不能为空");
        return;
    }
    axios
    ({

    })

    axios({
        url:'/api/Ward/AddWard',
        method:'post',
        data:query
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1)
        {
            alert("病房名称重复");
            return;
        }
        if(res.data>0)
        {
            alert("添加成功");
            router.push('/wardList');
            return;
        }
        else
        {
            alert("添加失败");
            return;
        }
        
    })
    .catch(err=>{
        console.log(err);
        
    })

}


</script>

<style scoped>

</style>